package com.smfx.yxt.controller.sys;

import java.util.ArrayList;
import java.util.List;

import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;
import org.springframework.web.servlet.ModelAndView;

import com.smfx.yxt.common.enums.ExcelTemplate;
import com.smfx.yxt.controller.BaseController;
import com.smfx.yxt.controller.MailboxPrincipalController;
import com.smfx.yxt.excel.JxlsExcelView;
import com.smfx.yxt.model.Grid;
import com.smfx.yxt.page.OrderBy;
import com.smfx.yxt.page.Page;
import com.smfx.yxt.reqVo.SchoolPropertyExportQueryVo;
import com.smfx.yxt.reqVo.StudentReqVO;
import com.smfx.yxt.reqVo.WorkApprovalCountQueryVO;
import com.smfx.yxt.service.IParentService;
import com.smfx.yxt.service.IPrincipalMailboxService;
import com.smfx.yxt.service.ISchoolPropertyService;
import com.smfx.yxt.service.IStudentService;
import com.smfx.yxt.service.ITeacherChangeCourseApplyService;
import com.smfx.yxt.service.ITeacherLeaveService;
import com.smfx.yxt.service.IWorkApprovalService;
import com.smfx.yxt.utils.BeanUtils;
import com.smfx.yxt.utils.DateUtil;
import com.smfx.yxt.view.CopyPaperApprovalView;
import com.smfx.yxt.view.OvertimeApplyView;
import com.smfx.yxt.view.ParentPersonImportView;
import com.smfx.yxt.view.PrincipalMailboxView;
import com.smfx.yxt.view.PrintingPaperApprovalView;
import com.smfx.yxt.view.SchoolBusApprovalView;
import com.smfx.yxt.view.SchoolPropertyConsumablesApplyExportView;
import com.smfx.yxt.view.SchoolPropertyInputExportView;
import com.smfx.yxt.view.SchoolPropertyLendAndReturnExportView;
import com.smfx.yxt.view.SchoolPropertyStockExportView;
import com.smfx.yxt.view.StudentPersonImportView;
import com.smfx.yxt.view.TeacherExchangeCourseApplyItemView;
import com.smfx.yxt.view.TeacherExchangeCourseApplyView;
import com.smfx.yxt.view.TeacherLeaveView;
import com.smfx.yxt.view.teachingGoodsApprovalView;
import com.smfx.yxt.vo.PrincipalMailboxQueryVO;
import com.smfx.yxt.vo.TeacherChangeCourseApplyQueryVO;
import com.smfx.yxt.vo.TeacherLeaveQueryVO;
import com.smfx.yxt.vo.WorkApprovalQueryVO;

/**
 * 报表
 * */
@RequestMapping("sys/report")
@Controller
public class ReportController extends BaseController {

	private Logger logger = LoggerFactory.getLogger(MailboxPrincipalController.class);
	@Autowired
	private IPrincipalMailboxService principalMailboxService;
	@Autowired
	private IWorkApprovalService workApprovalService;
	@Autowired
	private ITeacherLeaveService teacherLeaveService;
	@Autowired
	private ITeacherChangeCourseApplyService teacherChangeCourseApplyService;
	@Autowired
	private ISchoolPropertyService schoolPropertyService;
	@Autowired
	private IParentService parentService;
	@Autowired
	private IStudentService studentService;
	
	/**
	 * 校产库存报表
	 * */
	@RequestMapping("schoolPropertyStock")
	public String schoolPropertyStock() {
		return "sys/schoolPropertyStock";
	}
	
	/**
	 * 校产入库记录
	 * */
	@RequestMapping("schoolPropertyInput")
	public String schoolPropertyInput() {
		return "sys/schoolPropertyInput";
	}
	/**
	 * 校产消耗品领用
	 * */
	@RequestMapping("schoolPropertyConsumablesApply")
	public String schoolPropertyConsumablesApply() {
		return "sys/schoolPropertyConsumablesApply";
	}
	/**
	 * 校产非消耗品借还
	 * */
	@RequestMapping("schoolPropertyLendAndReturn")
	public String schoolPropertyLendAndReturn() {
		return "sys/schoolPropertyLendAndReturn";
	}
	
	/**
	 * 校长信箱
	 * */
	@RequestMapping("headmaster")
	public String headmasterIndex() {
		return "sys/headmaster";
	}
	/**
	 * 加班申请审批
	 * 
	 * */
	@RequestMapping("overtimeApply")
	public String overtimeApplyIndex() {
		return "sys/overtimeApplyIndex";
	}
	/**
	 * 打印纸申请审批
	 * 
	 * */
	@RequestMapping("printingPaper")
	public String printingPaperIndex() {
		return "sys/printingPaperIndex";
	}
	/**
	 * 校车审批
	 * 
	 * */
	@RequestMapping("schoolBus")
	public String schoolBusIndex() {
		return "sys/schoolBusIndex";
	}
	
	/**
	 * 教学用品申请审批
	 * 
	 * */
	@RequestMapping("teachingGoods")
	public String teachingGoodsIndex() {
		return "sys/teachingGoodsIndex";
	}
	/**
	 *复印油纸审批
	 * 
	 * */
	@RequestMapping("copyPaper")
	public String copyPaperIndex() {
		return "sys/copyPaperIndex";
	}
	/**
	 * 
	 * @return
	 */
	@RequestMapping("teacherLeave")
	public String teacherLeave() {
		return "sys/teacherLeave";
	}
	/**
	 * 代看课报表
	 * @return
	 */
	@RequestMapping("teacherReplaceCourse")
	public String teacherReplaceCourse() {
		return "sys/teacherReplaceCourse";
	}
	/**
	 * 调课报表
	 * @return
	 */
	@RequestMapping("teacherChangeCourse")
	public String teacherChangeCourse() {
		return "sys/teacherChangeCourse";
	}
	
	/**
	 * 校产报表
	 * */
	@RequestMapping(value ="schoolProperty/{type}")
	@ResponseBody
	public Grid schoolProperty(@PathVariable("type") String type,SchoolPropertyExportQueryVo vo) {
		try {
			Grid grid = new Grid();
			switch (type) {
			//库存管理
			case "stock":
				if(vo.getCycleUse() != null && vo.getCycleUse() == -1)
					vo.setCycleUse(null);
				if(vo.getTypeId() != null && vo.getTypeId() == -1)
					vo.setTypeId(null);
				Page<SchoolPropertyStockExportView> page = new Page<>();
				List<OrderBy> sorts = new ArrayList<>();
				sorts.add(new OrderBy("cycleUse", "desc"));
				sorts.add(new OrderBy("ID", "desc"));
				
				page.setSorts(sorts);
				page.setParams(vo);
				List<SchoolPropertyStockExportView> list = schoolPropertyService.selectAllStockForExportToExcelByPage(page);
				grid.setTotal(page.getTotalRecord());
				grid.setRows(list);
				break;
			//入库管理	
			case "inputRecord":
				if(vo.getStartTimeText() != null && vo.getStartTimeText() != "")
					vo.setStartTime(DateUtil.strToDate(vo.getStartTimeText() + " 00:00:00", DateUtil.DEFAULT_DATE_FORMAT));
				
				if(vo.getEndTimeText() != null && vo.getEndTimeText() != "")
					vo.setEndTime(DateUtil.strToDate(vo.getEndTimeText() + " 23:59:59", DateUtil.DEFAULT_DATE_FORMAT));
				
				Page<SchoolPropertyInputExportView> input = new Page<>();
				List<OrderBy> isorts = new ArrayList<>();
				isorts.add(new OrderBy("createTime", "desc"));
				input.setSorts(isorts);
				input.setParams(vo);
				List<SchoolPropertyInputExportView> inputList = schoolPropertyService.
						selectSchoolPropertyInputForExportToExcelByPage(input);
				grid.setTotal(input.getTotalRecord());
				grid.setRows(inputList);
				break;
			//消耗品领用	
			case "consumablesApply":{
				if(vo.getStartTimeText() != null && vo.getStartTimeText() != "")
					vo.setStartTime(DateUtil.strToDate(vo.getStartTimeText() + " 00:00:00", DateUtil.DEFAULT_DATE_FORMAT));
				
				if(vo.getEndTimeText() != null && vo.getEndTimeText() != "")
					vo.setEndTime(DateUtil.strToDate(vo.getEndTimeText() + " 23:59:59", DateUtil.DEFAULT_DATE_FORMAT));
				
				Page<SchoolPropertyConsumablesApplyExportView> ca = new Page<>();
				List<OrderBy> csorts = new ArrayList<>();
				csorts.add(new OrderBy("createTime", "DESC"));
				ca.setSorts(csorts);
				ca.setParams(vo);
				List<SchoolPropertyConsumablesApplyExportView> clist = schoolPropertyService.
						selectSchoolPropertyConsumablesApplyForExportToExcelByPage(ca);
				grid.setTotal(ca.getTotalRecord());
				grid.setRows(clist);
				break;
			}
			//非消耗品借还	
			case "lendAndReturn":{
				if(vo.getStartTimeText() != null && vo.getStartTimeText() != "")
					vo.setStartTime(DateUtil.strToDate(vo.getStartTimeText() + " 00:00:00", DateUtil.DEFAULT_DATE_FORMAT));
				
				if(vo.getEndTimeText() != null && vo.getEndTimeText() != "")
					vo.setEndTime(DateUtil.strToDate(vo.getEndTimeText() + " 23:59:59", DateUtil.DEFAULT_DATE_FORMAT));
				
				Page<SchoolPropertyLendAndReturnExportView> lrpage = new Page<>();
				List<OrderBy> lrsorts = new ArrayList<>();
				lrsorts.add(new OrderBy("state", "ASC"));
				lrsorts.add(new OrderBy("createTime", "DESC"));
				lrsorts.add(new OrderBy("updateTime", "DESC"));
				lrpage.setSorts(lrsorts);
				lrpage.setParams(vo);
				List<SchoolPropertyLendAndReturnExportView> lrList = schoolPropertyService.
						selectSchoolPropertyLendAndReturnForExportToExcelByPage(lrpage);
				grid.setTotal(lrpage.getTotalRecord());
				grid.setRows(lrList);
				break;
			}default:break;
		 }
			return grid;
		} catch (Exception e) {
			logger.error("schoolPropertyReport error ",e);
			return new Grid();
		}
	}
	/**
	 * 校产报表导出
	 * */
	@RequestMapping(value ="schoolProperty/export/{type}")
	public ModelAndView schoolPropertyReport(@PathVariable("type") String type,SchoolPropertyExportQueryVo vo,ModelAndView mv) {
		try {
			if(vo.getStartTimeText() != null && vo.getStartTimeText() != "")
				vo.setStartTime(DateUtil.strToDate(vo.getStartTimeText() + " 00:00:00", DateUtil.DEFAULT_DATE_FORMAT));
			
			if(vo.getEndTimeText() != null && vo.getEndTimeText() != "")
				vo.setEndTime(DateUtil.strToDate(vo.getEndTimeText() + " 23:59:59", DateUtil.DEFAULT_DATE_FORMAT));
			JxlsExcelView view = new JxlsExcelView();
			
			switch (type) {
			//库存管理
			case "stock":
				if(vo.getCycleUse() != null && vo.getCycleUse() == -1)
					vo.setCycleUse(null);
				if(vo.getTypeId() != null && vo.getTypeId() == -1)
					vo.setTypeId(null);
			
				List<SchoolPropertyStockExportView> list = schoolPropertyService.selectAllStockForExportToExcelByParams(vo);
				view.setTemplatePath(ExcelTemplate.SCHOOLPROPERTY_STOCK.getUrl());
				view.setExportFileName(ExcelTemplate.SCHOOLPROPERTY_STOCK.getName());
				mv.addObject("list", list);
				break;
			//入库管理	
			case "inputRecord":

				List<SchoolPropertyInputExportView> inputList = schoolPropertyService.selectSchoolPropertyInputForExportToExcelByParams(vo);
				view.setTemplatePath(ExcelTemplate.SCHOOLPROPERTY_INPUTRECORD.getUrl());
				view.setExportFileName(ExcelTemplate.SCHOOLPROPERTY_INPUTRECORD.getName());
				mv.addObject("list", inputList);
				break;
			//消耗品领用	
			case "consumablesApply":{
				
				List<SchoolPropertyConsumablesApplyExportView> clist = schoolPropertyService.
						selectSchoolPropertyConsumablesApplyForExportToExcelByParams(vo);
				view.setTemplatePath(ExcelTemplate.SCHOOLPROPERTY_CONSUMABLESAPPLY.getUrl());
				view.setExportFileName(ExcelTemplate.SCHOOLPROPERTY_CONSUMABLESAPPLY.getName());
				mv.addObject("list", clist);
				break;
			}
			//非消耗品借还	
			case "lendAndReturn":{
				
				List<SchoolPropertyLendAndReturnExportView> lrList = schoolPropertyService.
						selectSchoolPropertyLendAndReturnForExportToExcelByParams(vo);
				view.setTemplatePath(ExcelTemplate.SCHOOLPROPERTY_LENDANDRETURN.getUrl());
				view.setExportFileName(ExcelTemplate.SCHOOLPROPERTY_LENDANDRETURN.getName());
				mv.addObject("list", lrList);
				break;
			}default:break;
		  }
			
			mv.setView(view);
			return mv;
		} catch (Exception e) {
			logger.error("schoolPropertyReport error ",e);
			return mv;
		}
	}
	
	@RequestMapping("teacherLeave/page")
	@ResponseBody Object teacherLeavePage(TeacherLeaveQueryVO vo) {
		try {
			Page<TeacherLeaveView> page = new Page<>();
			Grid grid = new Grid();
			List<OrderBy> sorts = new ArrayList<>();
			sorts.add(new OrderBy("CREATE_TIME", "desc"));
			sorts.add(new OrderBy("UPDATE_TIME", "desc"));
			page.setSorts(sorts);
			page.setParams(vo);
			page.setPageNo(vo.getPage());
			page.setPageSize(vo.getRows());
			List<TeacherLeaveView> list = teacherLeaveService.selectListByPage(page);
			grid.setRows(list);
			grid.setTotal(page.getTotalRecord());
			return grid;
		} catch (Exception e) {
			logger.error("---teacherLeavePage error={}", e);
		}
		return null;
	}
	
	@RequestMapping("teacherLeave/export")
	ModelAndView teacherLeaveExport(ModelAndView modelAndView, TeacherLeaveQueryVO vo) {
		try {
			Page<TeacherLeaveView> page = new Page<>();
			List<OrderBy> sorts = new ArrayList<>();
			sorts.add(new OrderBy("CREATE_TIME", "desc"));
			sorts.add(new OrderBy("UPDATE_TIME", "desc"));
			page.setSorts(sorts);
			page.setParams(vo);
			page.setPageNo(vo.getPage());
			page.setPageSize(Integer.MAX_VALUE -1);
			List<TeacherLeaveView> list = teacherLeaveService.selectListByPage(page);
			
			JxlsExcelView view = new JxlsExcelView(ExcelTemplate.TEACHER_LEAVE);
			modelAndView.setView(view);
			modelAndView.getModelMap().put("list", list);
		} catch (Exception e) {
			logger.error("--teacherLeaveExport error ",e);
		}
		return modelAndView;
	}
	
	@RequestMapping("teacherChangeCourse/page")
	@ResponseBody Object teacherChangeCoursePage(TeacherChangeCourseApplyQueryVO vo) {
		try {
			Page<TeacherExchangeCourseApplyItemView> page = new Page<>();
			Grid grid = new Grid();
			List<OrderBy> sorts = new ArrayList<>();
			sorts.add(new OrderBy("CREATE_TIME", "desc"));
			sorts.add(new OrderBy("UPDATE_TIME", "desc"));
			page.setSorts(sorts);
			page.setParams(vo);
			page.setPageNo(vo.getPage());
			page.setPageSize(vo.getRows());
			List<TeacherExchangeCourseApplyItemView> list = teacherChangeCourseApplyService.selectReportListByPage(page);
			grid.setRows(list);
			grid.setTotal(page.getTotalRecord());
			return grid;
		} catch (Exception e) {
			logger.error("---teacherChangeCoursePage error={}", e);
		}
		return null;
	}
	
	@RequestMapping("teacherChangeCourse/export")
	ModelAndView teacherChangeCourseExport(ModelAndView modelAndView, TeacherChangeCourseApplyQueryVO vo) {
		try {
			Page<TeacherExchangeCourseApplyItemView> page = new Page<>();
			List<OrderBy> sorts = new ArrayList<>();
			sorts.add(new OrderBy("CREATE_TIME", "desc"));
			sorts.add(new OrderBy("UPDATE_TIME", "desc"));
			page.setSorts(sorts);
			page.setParams(vo);
			page.setPageNo(vo.getPage());
			page.setPageSize(Integer.MAX_VALUE -1);
			List<TeacherExchangeCourseApplyItemView> list = teacherChangeCourseApplyService.selectReportListByPage(page);
			JxlsExcelView view = new JxlsExcelView(ExcelTemplate.TEACHER_CHANGE_COURSE);
			modelAndView.setView(view);
			modelAndView.getModelMap().put("list", list);
		} catch (Exception e) {
			logger.error("--teacherChangeCourseExport error ",e);
		}
		return modelAndView;
	}
	
	/**
	 * 校长信箱查询
	 * */
	@RequestMapping(value = {"headmaster/list"})
	@ResponseBody Object principalMailboxQuery(PrincipalMailboxQueryVO vo) {
		try {
			Page<PrincipalMailboxView> page = new Page<>();
			Grid grid = new Grid();
			List<OrderBy> sorts = new ArrayList<>();
			sorts.add(new OrderBy("CREATE_TIME", "desc"));
			sorts.add(new OrderBy("REPLY_TIME", "desc"));
			page.setSorts(sorts);
			page.setParams(vo);
			page.setPageNo(vo.getPage());
			page.setPageSize(vo.getRows());
			if(vo.getIsReply() != null  && vo.getIsReply() == 10)
				  vo.setIsReply(null);
			if(vo.getSendTimeQuery()!= null)
				vo.setSendTime(DateUtil.strToDate(vo.getSendTimeQuery(),DateUtil.DEFAULT_DATE_FORMAT3 ));
			if(vo.getReplyTimeQuery() != null )
				vo.setReplyTime(DateUtil.strToDate( vo.getReplyTimeQuery(),DateUtil.DEFAULT_DATE_FORMAT3));
			
			List<PrincipalMailboxView> list = principalMailboxService.selectListByPage(page);
			grid.setRows(list);
			grid.setTotal(page.getTotalRecord());
			return grid;
		} catch (Exception e) {
			logger.error("---principalMailboxQuery error={}", e);
		}
		return null;
	}
	@RequestMapping(value = {"headmaster/export"})
	ModelAndView principalMailboxExport(ModelAndView modelAndView,PrincipalMailboxQueryVO vo) {
		try {
			
			Page<PrincipalMailboxView> page = new Page<>();
			List<OrderBy> sorts = new ArrayList<>();
			sorts.add(new OrderBy("CREATE_TIME", "desc"));
			sorts.add(new OrderBy("REPLY_TIME", "desc"));
			page.setSorts(sorts);
			page.setParams(vo);
			page.setPageNo(vo.getPage());
			page.setPageSize(Integer.MAX_VALUE -1);
			
			JxlsExcelView view = new JxlsExcelView(ExcelTemplate.HEADEMASTER_MAILBOX);
			modelAndView.setView(view);
			
			if(vo.getIsReply() != null  && vo.getIsReply() == 10)
				  vo.setIsReply(null);
			
			if(vo.getSendTimeQuery()!= null)
				vo.setSendTime(DateUtil.strToDate(vo.getSendTimeQuery(),DateUtil.DEFAULT_DATE_FORMAT3 ));
			if(vo.getReplyTimeQuery() != null )
				vo.setReplyTime(DateUtil.strToDate( vo.getReplyTimeQuery(),DateUtil.DEFAULT_DATE_FORMAT3));
			
			List<PrincipalMailboxView> list = principalMailboxService.selectListByPage(page);
			modelAndView.getModelMap().put("list", list);
		} catch (Exception e) {
			logger.error("principalMailboxExport error ",e);
		}
		return modelAndView;
	}
	
	/**
	 * 加班申请审批
	 * @param vo
	 * @return
	 */
	@RequestMapping("overtimeApply/list")
	@ResponseBody Grid overtimeApplyPageQuery(WorkApprovalQueryVO vo) {
		try {
			valid(vo);
			Page<OvertimeApplyView> page = new Page<OvertimeApplyView>();
			vo.setApprovalType("overtimeApply");
			Grid grid = new Grid();
			List<OrderBy> sorts = new ArrayList<>();
			sorts.add(new OrderBy("APPLY_TIME", "desc"));
			page.setSorts(sorts);
			page.setParams(vo);
			page.setPageNo(vo.getPage());
			page.setPageSize(vo.getRows());
			
			List<OvertimeApplyView> list = workApprovalService.selectWorkApprovalOfOvertimeApplyByPage(page);
		    grid.setRows(list);
			grid.setTotal(page.getTotalRecord());
			return grid;
		} catch (Exception e) {
			logger.error("--overtimeApplyPageQuery error={}", e);
		}
		 return new Grid();
	}
	
	/**
	 * 加班申请审批导出excel
	 * */
	@RequestMapping(value = "overtimeApply/export")
	public ModelAndView overtimeApplyExportToExcel(ModelAndView modelAndView,WorkApprovalQueryVO vo) {
		try {
			
			valid(vo);
			WorkApprovalCountQueryVO countVo = BeanUtils.copyAs(vo, WorkApprovalCountQueryVO.class);
			countVo.setApprovalType("overtimeApply");
			Integer size = workApprovalService.countAllRecord(countVo);
			vo.setRows(size + 1);
			
			Grid schoolBusPageQuery = overtimeApplyPageQuery(vo);
			
			modelAndView.getModelMap().addAttribute("list", schoolBusPageQuery.getRows());
			
			JxlsExcelView view = new JxlsExcelView(ExcelTemplate.OVERTIME_APPLY);
			
			modelAndView.setView(view);
		} catch (Exception e) {
			logger.error("--overtimeApplyExportToExcel error={}", e);
		}
		return modelAndView;
	}

	/**
	 *  校车审批查询
	 * @param vo
	 * @return
	 */
	@RequestMapping("schoolBus/list")
	@ResponseBody Grid schoolBusPageQuery(WorkApprovalQueryVO vo) {
		try {
			valid(vo);
			Page<SchoolBusApprovalView> page = new Page<SchoolBusApprovalView>();
			vo.setApprovalType("schoolBus");
			Grid grid = new Grid();
			List<OrderBy> sorts = new ArrayList<>();
			sorts.add(new OrderBy("APPLY_TIME", "desc"));
			sorts.add(new OrderBy("APPROVAL_TIME", "desc"));
			page.setSorts(sorts);
			page.setParams(vo);
			page.setPageNo(vo.getPage());
			page.setPageSize(vo.getRows());
			List<SchoolBusApprovalView> list = workApprovalService.selectWorkApprovalOfSchoolbusByPage(page);
			grid.setRows(list);
			grid.setTotal(page.getTotalRecord());
			return grid;
		} catch (Exception e) {
			logger.error("--schoolBusPageQuery error={}", e);
		}
		 return new Grid();
	}
	/**
	 * 校车审批导出excel表
	 * */
	@RequestMapping(value = "schoolBus/export")
	public ModelAndView schoolBusExportToExcel(ModelAndView modelAndView,WorkApprovalQueryVO vo) {
		try {
			
			valid(vo);
			WorkApprovalCountQueryVO countVo = BeanUtils.copyAs(vo, WorkApprovalCountQueryVO.class);
			countVo.setApprovalType("schoolBus");
			Integer size = workApprovalService.countAllRecord(countVo);
			
			JxlsExcelView view = new JxlsExcelView(ExcelTemplate.SCHOOL_BUS);
			modelAndView.setView(view);
			
			vo.setRows(size + 1);
			Grid schoolBusPageQuery = schoolBusPageQuery(vo);
			modelAndView.getModelMap().addAttribute("list", schoolBusPageQuery.getRows());
			
		} catch (Exception e) {
			logger.error("--schoolBusExportToExcel error={}", e);
		}
		return modelAndView;
	}
	
	
	/**
	 * 教学用品申请审批查询
	 * */
	@RequestMapping("teachingGoods/list")
	@ResponseBody Grid teachingGoodsPageQuery(WorkApprovalQueryVO vo) {
		try {

			valid(vo);
			Page<teachingGoodsApprovalView> page = new Page<>();
			vo.setApprovalType("teachingGoods");
			Grid grid = new Grid();
			List<OrderBy> sorts = new ArrayList<>();
			sorts.add(new OrderBy("APPLY_TIME", "desc"));
			sorts.add(new OrderBy("APPROVAL_TIME", "desc"));
			page.setSorts(sorts);
			page.setParams(vo);
			page.setPageNo(vo.getPage());
			page.setPageSize(vo.getRows());
			List<teachingGoodsApprovalView> list = workApprovalService.selectWorkApprovalOfTeachingGoodsByPage(page);

			grid.setRows(list);
			grid.setTotal(page.getTotalRecord());
			return grid;
		} catch (Exception e) {
			logger.error("--teachingGoodsPageQuery error={}", e);
		}
		 return new Grid();
	}
	
	/**
	 * 教学用品审批导出excel表
	 * */
	@RequestMapping(value = "teachingGoods/export")
	public ModelAndView teachingGoodsExportToExcel(ModelAndView modelAndView,WorkApprovalQueryVO vo) {
		try {
			valid(vo);
			WorkApprovalCountQueryVO countVo = BeanUtils.copyAs(vo, WorkApprovalCountQueryVO.class);
			countVo.setApprovalType("teachingGoods");
			Integer size = workApprovalService.countAllRecord(countVo);
			
			vo.setRows(size + 1);
			Grid grid = teachingGoodsPageQuery(vo);
			
			modelAndView.getModelMap().addAttribute("list", grid.getRows());
			
			JxlsExcelView view = new JxlsExcelView(ExcelTemplate.TEACHING_GOODS);
			
			modelAndView.setView(view);
		} catch (Exception e) {
			logger.error("--teachingGoodsExportToExcel error={}", e);
		}
		return modelAndView;
	}
	
	/**
	 *复印油纸审批查询
	 * 
	 * */
	@RequestMapping("copyPaper/list")
	@ResponseBody Grid copyPaperPageQuery(WorkApprovalQueryVO vo) {
		try {
			valid(vo);
			Page<CopyPaperApprovalView> page = new Page<CopyPaperApprovalView>();
			vo.setApprovalType("copyPaper");
			Grid grid = new Grid();
			List<OrderBy> sorts = new ArrayList<>();
			sorts.add(new OrderBy("APPLY_TIME", "desc"));
			sorts.add(new OrderBy("APPROVAL_TIME", "desc"));
			page.setSorts(sorts);
			page.setParams(vo);
			page.setPageNo(vo.getPage());
			page.setPageSize(vo.getRows());
			List<CopyPaperApprovalView> list = workApprovalService.selectWorkApprovalOfCopyPaperByPage(page);
			grid.setRows(list);
			grid.setTotal(page.getTotalRecord());
			return grid;
		} catch (Exception e) {
			logger.error("--copyPaperPageQuery error={}", e);
		}
		 return new Grid();
	}
	
	
	/**
	 * 复印油纸审批导出excel
	 * */
	@RequestMapping(value = "copyPaper/export")
	public ModelAndView copyPaperExportToExcel(ModelAndView modelAndView,WorkApprovalQueryVO vo) {
		try {
			
			valid(vo);
			WorkApprovalCountQueryVO countVo = BeanUtils.copyAs(vo, WorkApprovalCountQueryVO.class);
			countVo.setApprovalType("copyPaper");
			Integer size = workApprovalService.countAllRecord(countVo);
			System.out.println(size);
			vo.setRows(size + 1);
			Grid schoolBusPageQuery = copyPaperPageQuery(vo);
			
			modelAndView.getModelMap().addAttribute("list", schoolBusPageQuery.getRows());
			
			JxlsExcelView view = new JxlsExcelView(ExcelTemplate.COPY_PAPER);
			
			modelAndView.setView(view);
		} catch (Exception e) {
			logger.error("--copyPaperExportToExcel error={}", e);
		}
		return modelAndView;
	}
	
	/**
	 * 打印纸申请审批
	 * PrintingPaperApprovalView
	 * */
	@RequestMapping("printingPaper/list")
	@ResponseBody Grid printingPaperApprovalPageQuery(WorkApprovalQueryVO vo) {
		try {
			valid(vo);
			
			vo.setApprovalType("printingPaper");
			
			Page<PrintingPaperApprovalView> page = new Page<>();
			List<OrderBy> sorts = new ArrayList<>();
			sorts.add(new OrderBy("APPLY_TIME", "desc"));
			sorts.add(new OrderBy("APPROVAL_TIME", "desc"));
			page.setSorts(sorts);
			page.setParams(vo);
			page.setPageNo(vo.getPage());
			page.setPageSize(vo.getRows());
			List<PrintingPaperApprovalView> list = workApprovalService.selectWorkApprovalOfPrintingPaperByPage(page);
			Grid grid = new Grid();
			grid.setRows(list);
			grid.setTotal(page.getTotalRecord());
			return grid;
		} catch (Exception e) {
			logger.error("--printingPaperApprovalPageQuery error={}", e);
		}
		 return new Grid();
	}
	
	/**
	 * 打印纸申请审批导出excel
	 * */
	@RequestMapping(value = "printingPaper/export")
	public ModelAndView printingPaperExportToExcel(ModelAndView modelAndView,WorkApprovalQueryVO vo) {
		try {
			
			valid(vo);
			WorkApprovalCountQueryVO countVo = BeanUtils.copyAs(vo, WorkApprovalCountQueryVO.class);
			countVo.setApprovalType("printingPaper");
			Integer size = workApprovalService.countAllRecord(countVo);
			
			vo.setRows(size + 1);
			Grid schoolBusPageQuery = printingPaperApprovalPageQuery(vo);
			
			modelAndView.getModelMap().addAttribute("list", schoolBusPageQuery.getRows());
			
			JxlsExcelView view = new JxlsExcelView(ExcelTemplate.PRINTING_PAPER);
			
			modelAndView.setView(view);
		} catch (Exception e) {
			logger.error("--printingPaperExportToExcel error={}", e);
		}
		return modelAndView;
	}
	
	private void valid(WorkApprovalQueryVO vo) {
		if("111".equals(vo.getApprovalStatus()))
			vo.setApprovalStatus(null);
		if(vo.getApplyTimeQuery() != null) {
			vo.setApplyTime( DateUtil.strToDate(vo.getApplyTimeQuery(), DateUtil.DEFAULT_DATE_FORMAT3));
		}
		if(vo.getApprovalTimeQuery() != null) {
			vo.setApprovalTime( DateUtil.strToDate(vo.getApprovalTimeQuery(), DateUtil.DEFAULT_DATE_FORMAT3));
		}
	}
	
	
	@RequestMapping("studentForHkExport")
	ModelAndView studentForHkExport(ModelAndView modelAndView, StudentReqVO vo) {
		try {
			
			Page<StudentPersonImportView> page = new Page<>();
			List<OrderBy> sorts = new ArrayList<>();
			sorts.add(new OrderBy("grade"));
			sorts.add(new OrderBy("clazz"));
			sorts.add(new OrderBy("学号"));
			page.setSorts(sorts);
			page.setParams(vo);
			page.setPageNo(vo.getPage());
			page.setPageSize(Integer.MAX_VALUE -1);
			
			JxlsExcelView view = new JxlsExcelView(ExcelTemplate.STUDENT_PERSON_IMPORT);
			modelAndView.setView(view);
			
			List<StudentPersonImportView> list = studentService.selectPersonImport(page);
			modelAndView.getModelMap().put("list", list);
		
		} catch (Exception e) {
			logger.error("studentExport error ",e);
		}
		return modelAndView;
	}
	
	@RequestMapping("parentForHkExport")
	ModelAndView parentForHkExport(ModelAndView modelAndView, StudentReqVO vo) {
		try {
			Page<ParentPersonImportView> page = new Page<>();
			List<OrderBy> sorts = new ArrayList<>();
			sorts.add(new OrderBy("grade"));
			sorts.add(new OrderBy("clazz"));
			page.setSorts(sorts);
			page.setParams(vo);
			page.setPageNo(vo.getPage());
			page.setPageSize(Integer.MAX_VALUE -1);
			
			JxlsExcelView view = new JxlsExcelView(ExcelTemplate.PARENT_PERSON_IMPORT);
			modelAndView.setView(view);
			
			List<ParentPersonImportView> list = parentService.selectPersonImport(page);
			modelAndView.getModelMap().put("list", list);
		} catch (Exception e) {
			logger.error("parentExport error ",e);
		}
		return modelAndView;
	}
}
